﻿using System;
using DNT.TaxCalculationChallenge.Core;
using NUnit.Framework;
using Rhino.Mocks;

namespace DNT.TaxCalculationChallenge.TestFixtures
{
    [TestFixture]
    public class RangeTaxPolicyFixtures
    {
        [Test]
        public void RangeTaxPolicy_Appliance_Tests()
        {
            var instance = new RangeTaxPolicy<Decimal>(new DefaultRangeOverlapAlgorithm<Decimal>(), Decimal.Zero, 5070M, 0.1M);
            Assert.That(500M, Is.EqualTo(instance.Apply(5000M)));
        }

        [Test]
        public void RangeTaxPolicy_Equality_Tests()
        {
            var fakeAlgorithm = new MockRepository().Stub<IRangeOverlapAlgorithm<Decimal>>();

            var policy1 = new RangeTaxPolicy<Decimal>(fakeAlgorithm, Decimal.Zero, 5070M, 0.1M);
            Assert.That(policy1, Is.EqualTo(policy1));
            Assert.That(policy1.GetHashCode(), Is.EqualTo(policy1.GetHashCode()));

            Assert.That(policy1, Is.Not.EqualTo(null));
            Assert.That((Object)null, Is.Not.EqualTo(policy1));

            var policy2 = new RangeTaxPolicy<Decimal>(fakeAlgorithm, Decimal.Zero, 5070M, 0.1M);
            Assert.That(policy1, Is.EqualTo(policy2));
            Assert.That(policy2, Is.EqualTo(policy1));
            Assert.That(policy1.GetHashCode(), Is.EqualTo(policy2.GetHashCode()));

            var policy3 = new RangeTaxPolicy<Decimal>(fakeAlgorithm, Decimal.Zero, 5071M, 0.1M);
            Assert.That(policy1, Is.Not.EqualTo(policy3));
            Assert.That(policy1.GetHashCode(), Is.Not.EqualTo(policy3.GetHashCode()));
            Assert.That(policy2, Is.Not.EqualTo(policy3));
            Assert.That(policy2.GetHashCode(), Is.Not.EqualTo(policy3.GetHashCode()));
        }
    }
}